//
//  Segment.m
//  云成绩
//
//  Created by Apple1 on 2017/3/4.
//  Copyright © 2017年 zj. All rights reserved.
//

#import "Segment.h"

@implementation Segment

- (void)setUnselectFontSize:(CGFloat)unselectFontSize {
    
    _unselectFontSize = unselectFontSize;
    
    NSMutableDictionary *unseletStyle = [self titleTextAttributesForState:UIControlStateNormal].mutableCopy;
    
    unseletStyle[NSFontAttributeName] = [UIFont systemFontOfSize:_unselectFontSize];
    
    [self setTitleTextAttributes:unseletStyle forState:UIControlStateNormal];
}

- (void)setUnselectFontColor:(UIColor *)unselectFontColor {
    
    _unselectFontColor = unselectFontColor;
    
    NSMutableDictionary *unseletStyle = [self titleTextAttributesForState:UIControlStateNormal].mutableCopy;
    
    unseletStyle[NSForegroundColorAttributeName] = _unselectFontColor;
    
    [self setTitleTextAttributes:unseletStyle forState:UIControlStateNormal];
    
}

- (void)setSelectFontColor:(UIColor *)selectFontColor {
    
    _selectFontColor = selectFontColor;
    
    NSMutableDictionary *unseletStyle = [self titleTextAttributesForState:UIControlStateSelected].mutableCopy;
    
    unseletStyle[NSForegroundColorAttributeName] = _selectFontColor;
    
    [self setTitleTextAttributes:unseletStyle forState:UIControlStateSelected];//设置文字属性
}

- (void)setSelectFontSize:(CGFloat)selectFontSize {
    
    _selectFontSize = selectFontSize;
    
    NSMutableDictionary *unseletStyle = [self titleTextAttributesForState:UIControlStateSelected].mutableCopy;
    
    unseletStyle[NSFontAttributeName] = [UIFont systemFontOfSize:_selectFontSize];
    
    [self setTitleTextAttributes:unseletStyle forState:UIControlStateSelected];//设置文字属性
}

- (void)setTinColor:(UIColor *)tinColor {
    
    _tinColor = tinColor;
    
    self.tintColor = _tinColor;
    
    self.momentary = NO;
    
}

- (void)setCornRadius:(CGFloat )cornRadius {
    _cornRadius = cornRadius;
    self.layer.cornerRadius = _cornRadius;
    
}

- (void)setSelectImgStr:(NSString *)selectImgStr {
    
    _selectImgStr = selectImgStr;
    
    [self setBackgroundImage:[UIImage imageNamed:_selectImgStr] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    
}

- (void)setNormalImgStr:(NSString *)normalImgStr {
    _normalImgStr = normalImgStr;
    
    [self setBackgroundImage:[UIImage imageNamed:_normalImgStr] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
    if (newSuperview == nil) return;
    
    [self setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_unselectFontSize], NSForegroundColorAttributeName:_unselectFontColor ?: [UIColor darkGrayColor]} forState:UIControlStateNormal];
    
    [self setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:_selectFontSize], NSForegroundColorAttributeName:_selectFontColor ?: (self.tintColor)} forState:UIControlStateSelected];


    [self addTarget:self action:@selector(didClicksegmentedControlAction:) forControlEvents:UIControlEventValueChanged];
    
    self.layer.masksToBounds = YES;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

-(void)didClicksegmentedControlAction:(UISegmentedControl *)Seg{
    
    [_tagert performSelector:_action withObject:Seg afterDelay:0];
    
}


@end
